package socket.nio.demo_01;

import java.io.IOException;
import java.io.InputStreamReader;
import java.net.InetSocketAddress;
import java.net.Socket;

public class ChargenClient2 {
    public static int DEFAULT_PORT = 1024;

    public static void main(String[] args) {
        try {
            Socket client = new Socket();
            client.connect(new InetSocketAddress("localhost", DEFAULT_PORT));
            InputStreamReader in = new InputStreamReader(client.getInputStream(), "ASCII");

            StringBuffer buffer = new StringBuffer();
            for(int c = in.read(); c != -1; c = in.read()) {
                buffer.append((char) c);
                if((char) c == '\r' || (char) c == '\n') {
                    System.out.print(buffer);
                    buffer = new StringBuffer();
                }
            }

        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
